﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Billing.Utilities;
using System.Diagnostics;
using System.Configuration;

namespace Billing.Windows
{
    public partial class SyncRates : Window
    {
        public SyncRates()
        {
            InitializeComponent();
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.F1)
                {
                    Process p = new Process();
                    p.StartInfo.WorkingDirectory = ConfigurationManager.AppSettings["BackGroundSyncerPath"];
                    p.StartInfo.FileName = p.StartInfo.WorkingDirectory + "\\BackgroundSyncer.exe";
                    p.StartInfo.CreateNoWindow = true;
                    p.Start();
                    p.WaitForExit();
                    this.Close();
                    //if (MessageBoxResult.Yes == MessageBox.Show("Do you want to sync rates from Server? Server will be Hanged for few seconds.", "Sync Rates", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No))
                    //{
                    //    if (Database.SyncRatesFromServer() >= 0)
                    //    {
                    //        MessageBox.Show("Rates Successfully Updated", "Rates Synced", MessageBoxButton.OK, MessageBoxImage.Information);
                    //        CacheManager.ResetCacheManager();
                    //        this.Close();
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("Some Unknown Error has occurred. Please Try Later", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    //    }
                    //}
                }
                else if (e.Key == Key.Escape)
                {
                    this.Close();
                }
            }
            catch (Exception) { }
        }
    }
}
